/**
 * Desenvolvido pela Fábrica de Software do CESUPA.
 * Todos os direitos reservados.
 */
package br.cesupa.fabsoft.nomedoprojeto.modules.systemmodule.beans;

import br.cesupa.fabsoft.nomedoprojeto.modules.systemmodule.dataaccess.Message;
import br.cesupa.fabsoft.nomedoprojeto.modules.systemmodule.dataaccess.MessageType;
import br.cesupa.fabsoft.nomedoprojeto.utils.ManagedBeanUtils;

/**
 * Bean used to control application status messages.
 *
 * @author Breno Leite
 */
public class MessageBean {

    /**
     * Message status of the last operation executed in the system.
     */
    private Message applicationMessage = null;
    /**
     * If the message should be rendered or not.
     */
    private boolean applicationMessageActive = false;

    public MessageBean() {
    }

    public String closeMessage() {
        setApplicationMessageActive(false);
        return null;
    }

    public static MessageBean getCurrentInstance() {
        return (MessageBean) ManagedBeanUtils.getManagedBeanCurrentInstance("MessageBean");
    }

    /**
     * @return the applicationMessage
     */
    public Message getApplicationMessage() {
        return applicationMessage;
    }

    /**
     * @param applicationMessage the applicationMessage to set
     */
    public void displayMessage(Message applicationMessage) {
        this.applicationMessage = applicationMessage;
        applicationMessageActive = true;
    }

    public void displayMessage(String message) {
        this.applicationMessage = new Message(message, MessageType.INFO);
        applicationMessageActive = true;
    }

    public void displayMessage(String message, MessageType messageType) {
        this.applicationMessage = new Message(message, messageType);
        applicationMessageActive = true;
    }

    /**
     * @return the applicationMessageActive
     */
    public boolean isApplicationMessageActive() {
        return applicationMessageActive;
    }

    /**
     * @param applicationMessageActive the applicationMessageActive to set
     */
    public void setApplicationMessageActive(boolean applicationMessageActive) {
        this.applicationMessageActive = applicationMessageActive;
    }
}
